package com.hongxun.design.ui.headandbottonpanel;

import android.content.Context;
import android.graphics.Color;
import android.util.AttributeSet;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.hongxun.design.R;
import com.hongxun.design.bean.HeadSecondBean;
import com.hongxun.design.mytools.IconSourse;
import com.hongxun.design.mytools.SetTypeface;

//import peiwang.peiwang.R;

//import Constant;

public class HeadSecondControlPanel extends RelativeLayout {


    public TextView mleftTitle,share;
    public TextView mRightTitle;
    public TextView title;
    private HeadSecondControlPanel midle_bar;
    RelativeLayout search;
    public TextView stitle, sIcon;
    private static final int default_background_color = Color.rgb(255, 255, 255);

    public HeadSecondControlPanel(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    protected void onFinishInflate() {
        super.onFinishInflate();
        mleftTitle = (TextView) findViewById(R.id.headsecond_back);
        mRightTitle = (TextView) findViewById(R.id.headsecond_right);
        title = (TextView) findViewById(R.id.headsecond_title);
        share = (TextView) findViewById(R.id.headsecond_share);
        midle_bar = (HeadSecondControlPanel) findViewById(R.id.headsecond_bar);
        search = (RelativeLayout) findViewById(R.id.headsecond_search);
        stitle = (TextView) search.findViewById(R.id.headsecond_search_title);
        sIcon = (TextView) search.findViewById(R.id.headsecond_search_icon);
        SetTypeface.set(sIcon, IconSourse.change);
        setBackgroundColor(default_background_color);
    }

    public void setSearchTitle(String title) {
        stitle.setText(title);
        this.title.setVisibility(GONE);
        this.search.setVisibility(VISIBLE);
    }

    public void setSearchOnclick(OnClickListener searchOnclick) {
        search.setOnClickListener(searchOnclick);
    }

    public void initHeadPanel(HeadSecondBean bean) {
        mleftTitle.setOnClickListener(bean.getListener());
        SetTypeface.set(mleftTitle, bean.getLeft_icon());
        mleftTitle.setVisibility(bean.getLeft_ishide());

        title.setText(bean.getTitle());
//        title.setTextColor(mColor(bean.getTitle_color()));
        title.setVisibility(bean.getIshide());

        SetTypeface.set(mRightTitle, bean.getRight_icon());
        if (bean.getRight_ishide() == View.GONE) {
            mRightTitle.setVisibility(INVISIBLE);
        } else {
            mRightTitle.setVisibility(bean.getRight_ishide());
        }

        mRightTitle.setTextColor(mColor(bean.getRight_color()));

    }

    /**
     * 设置标题风格变为透明*
     */
    public void setTransparentStyle() {
        midle_bar.setBackgroundResource(R.color.translucent);
        title.setTextColor(getResources().getColor(R.color.white));
        mRightTitle.setTextColor(getResources().getColor(R.color.white));
        mleftTitle.setTextColor(getResources().getColor(R.color.white));
    }

    private int mColor(int color) {
        if (color == -1) color = R.color.gray;
        return getResources().getColor(color);
    }

    public void setClickListener(OnClickListener listener) {
        mRightTitle.setOnClickListener(listener);
    }

    public void reMoveOnClickListener() {
        mRightTitle.setOnClickListener(null);
    }


    public void setTitle(String name) {
        title.setText(name);
    }
}
